//
//  SwiftDemo.swift
//  SwiftDemo
//
//  Created by 硕星 on 2019/4/22.
//  Copyright © 2019 ty. All rights reserved.
//

import Foundation
import RxSwift
import Moya
import Alamofire


enum NetAPI {
    case Login(username:String, password:String)
    case Banners
}

extension NetAPI: TargetType{
    
    var parameterEncoding: ParameterEncoding{
        return URLEncoding.default
    }
    
    var baseURL: URL {
        return URL(string: BaseUrl)!
    }
    
    var path: String {
        switch self {
        case .Login(_,_):
            return "/djdp/index.php/Api/Help/indexSlide"
        case .Banners:
            return "/djdp/index.php/Api/Help/indexSlide"
        }
    }
    
    var method: Moya.Method {
        switch self {
        case .Login(_, _):
            return .get
        case .Banners:
            return .get
        }
    }
    
    var sampleData: Data {
        switch self {
        case .Login(_, _):
            return "Login success".data(using: String.Encoding.utf8)!
        case .Banners:
            return "Login success".data(using: String.Encoding.utf8)!
        }
    }
    
    var task: Task {
        return .requestPlain
    }
    
    var headers: [String : String]? {
        switch self {
        case .Login(let username, let password):
            return ["username": username, "password": password]
        case .Banners:
            return nil
        }
    }
    
}
let netApi = MoyaProvider<NetAPI>()
